home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*------------------------------------------------------------------------------
- *
- * OORT - radar.c - Routines for displaying the radar.
- *
- * $Id: radar.c,v 1.2 1994/01/28 00:20:51 mtj Exp $
- *
- * Chris Fouts - May, 1993.
- *
- *----------------------------------------------------------------------------*/
- #include <stdio.h>
- #include <gl.h>
-
- #include "oort.h"
- #include "radar.h"
-
- /* BEGIN PROTOTYPES -S radar.c */
- /* END PROTOTYPES -S radar.c */
-
-
- static Object radarObj ;
- static float radarAlt = (float)( 2.0f * ASTEROID_RADIUS ) ;
- static float radarMags[] = {
- 0.10f, 0.25f, 0.5f, 1.0f, 2.0f,
- } ;
- static int radarSetting = 4 ;
-
- extern pfVec3 teamColor[] ;
- extern int debugOn ;
- extern int selfStatus ;
- extern int numberPlayers ;
- extern float longitude ;
- extern float latitude ;
- extern pfVec3 up ;
- extern pfVec3 ahead ;
- extern pfVec3 right ;
- extern Motion motion ;
- extern ViewPort radarVP ;
- extern Player player[] ;
-
-
-
- /*------------------------------------------------------------------------------
- * Create the terrain background object.
- *----------------------------------------------------------------------------*/
- void
- makeRadarBackground(
- int lats,
- int lngs
- )
- {
- int i ;
- int j ;
- float phi ;
- float theta ;
- float sp ;
- float cp ;
- float st ;
- float ct ;
- float r = ASTEROID_RADIUS ;
- pfVec3 v ;
-
- radarObj = genobj() ;
-
- makeobj( radarObj ) ;
- cpack( 0x0 ) ;
- clear() ;
- cpack( 0x00ff0000 ) ;
- for( i = 1 ; i < lngs ; i++ )
- {
- theta = 360.0f * i / (float)lngs ;
- pfSinCos( theta, &st, &ct ) ;
- bgnline() ;
- for( j = 0 ; j < lats ; j++ )
- {
- phi = 180.0f * j / ( lats - 1.0f ) ;
- pfSinCos( phi, &sp, &cp ) ;
- PFSET_VEC3( v, r*sp*st, -r*sp*ct, r*cp ) ;
- v3f( v ) ;
- }
- endline() ;
- }
- for( j = 1 ; j < lats - 1 ; j++ )
- {
- if( j != ( lats - 1 ) / 2 )
- {
- phi = 180.0f * j / ( lats - 1.0f ) ;
- pfSinCos( phi, &sp, &cp ) ;
- bgnline() ;
- for( i = 0 ; i <= lngs ; i++ )
- {
- theta = 360.0f * i / (float)lngs ;
- pfSinCos( theta, &st, &ct ) ;
- PFSET_VEC3( v, r*sp*st, -r*sp*ct, r*cp );
- v3f( v ) ;
- }
- endline() ;
- }
- }
- cpack( 0x00ffff00 ) ;
- st = 0.0f ;
- ct = 1.0f ;
- bgnline() ;
- for( j = 0 ; j < lats ; j++ )
- {
- phi = 180.0f * j / ( lats - 1.0f ) ;
- pfSinCos( phi, &sp, &cp ) ;
- PFSET_VEC3( v, r*sp*st, -r*sp*ct, r*cp ) ;
- v3f( v ) ;
- }
- endline() ;
- sp = 1.0f ;
- cp = 0.0f ;
- bgnline() ;
- for( i = 0 ; i <= lngs ; i++ )
- {
- theta = 360.0f * i / (float)lngs ;
- pfSinCos( theta, &st, &ct ) ;
- PFSET_VEC3( v, r*sp*st, -r*sp*ct, r*cp ) ;
- v3f( v ) ;
- }
- endline() ;
- closeobj() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show the radar.
- *----------------------------------------------------------------------------*/
- void
- showRadar(
- void
- )
- {
- int i ;
- float ada ;
- float zFar ;
- float l ;
- float st ;
- float ct ;
- float sp ;
- float cp ;
- pfVec3 a ; /* radar ahead (looking down) */
- pfVec3 u ; /* radar up (looking forward) */
- pfVec3 r ; /* radar right (looking right) */
- pfVec3 loc ;
- pfMatrix m ;
- pfMatrix invRot ;
- pfVec3 blip[4] ;
- pfVec2 c ;
-
- if( selfStatus == OORT_ST_ON_GROUND )
- {
- PFSCALE_VEC3( a, -1.0f, motion.cg ) ;
- pfNormalizeVec3( a ) ;
-
- ada = PFDOT_VEC3( ahead, a ) ;
-
- /*
- * If ahead vector is either pointing straight up or down, key
- * off of up vector.
- */
- if( ada < -0.9999f && 0.9999f < ada )
- {
- ADDSCALE_VEC3( u, up, -PFDOT_VEC3( up, a ), a ) ;
- pfNormalizeVec3( u ) ;
- }
- /*
- * otherwise, use ahead vector.
- */
- else
- {
- ADDSCALE_VEC3( u, ahead, -ada, a ) ;
- pfNormalizeVec3( u ) ;
- }
- pfCrossVec3( r, a, u ) ;
-
- PFSCALE_VEC3( loc, ASTEROID_RADIUS, a ) ;
- }
- else
- {
- pfSinCos( longitude, &st, &ct ) ;
- pfSinCos( latitude, &sp, &cp ) ;
- PFSET_VEC3( a, -cp*st, cp*ct, -sp ) ;
- PFSET_VEC3( r, ct, st, 0.0f ) ;
- pfCrossVec3( u, r, a ) ;
-
- PFSET_VEC3( loc, -cp*st, cp*ct, -sp ) ;
- PFSCALE_VEC3( loc, ASTEROID_RADIUS, loc ) ;
- }
-
- /*
- * Rotation and height of view matrix.
- */
- m[0][0] = r[0] ; m[1][0] = r[1] ; m[2][0] = r[2] ;
- m[0][1] = u[0] ; m[1][1] = u[1] ; m[2][1] = u[2] ;
- m[0][2] = -a[0] ; m[1][2] = -a[1] ; m[2][2] = -a[2] ;
- m[3][0] = 0.0f ; m[3][1] = 0.0f ; m[3][2] = -radarAlt ;
- m[0][3] = 0.0f ; m[1][3] = 0.0f ; m[2][3] = 0.0f ; m[3][3] = 1.0f ;
-
- /*
- * Inverse rotation matrix (keeps radar blips orthogonal to line
- * of sight).
- */
- invRot[0][0] = r[0] ; invRot[0][1] = r[1] ; invRot[0][2] = r[2] ;
- invRot[1][0] = u[0] ; invRot[1][1] = u[1] ; invRot[1][2] = u[2] ;
- invRot[2][0] = -a[0] ; invRot[2][1] = -a[1] ; invRot[2][2] = -a[2] ;
- invRot[3][0] = 0.0f ; invRot[3][1] = 0.0f ; invRot[3][2] = 0.0f ;
- invRot[0][3] = 0.0f ; invRot[1][3] = 0.0f ; invRot[2][3] = 0.0f ;
- invRot[3][3] = 1.0f ;
-
- /*
- * Calculate size of radar blip so it's always the same size.
- */
- l = radarAlt * (float)( 2.0f*CAR_LENGTH / ( 0.25f*ASTEROID_RADIUS ) ) ;
-
- PFSET_VEC3( blip[0], -l, -l, 0.0f ) ;
- PFSET_VEC3( blip[1], l, -l, 0.0f ) ;
- PFSET_VEC3( blip[2], -l, l, 0.0f ) ;
- PFSET_VEC3( blip[3], l, l, 0.0f ) ;
-
- /*
- * Rotate blip so it always faces us.
- */
- pfXformVec3( blip[0], blip[0], invRot ) ;
- pfXformVec3( blip[1], blip[1], invRot ) ;
- pfXformVec3( blip[3], blip[3], invRot ) ;
- pfXformVec3( blip[2], blip[2], invRot ) ;
-
- viewport( radarVP.left, radarVP.right, radarVP.bottom,
- radarVP.top ) ;
-
- /*
- * Calculate zFar such that we only see the surface of the asteroid
- * facing us.
- */
- zFar = radarAlt + ASTEROID_RADIUS ;
- zFar = zFar - (float)( ASTEROID_RADIUS * ASTEROID_RADIUS ) / zFar ;
- perspective( 450, 1.0f, 1.0f, zFar ) ;
-
- loadmatrix( m ) ;
- translate( loc[0], loc[1], loc[2] ) ;
-
- callobj( radarObj ) ;
-
- /*
- * Draw self on radar as open square.
- */
- if( selfStatus == OORT_ST_ON_GROUND )
- {
- c3f( teamColor[player[SELF].team] ) ;
- pushmatrix() ;
- translate( player[SELF].xyz[0], player[SELF].xyz[1],
- player[SELF].xyz[2] ) ;
- bgnclosedline() ;
- v3f( blip[0] ) ;
- v3f( blip[1] ) ;
- v3f( blip[3] ) ;
- v3f( blip[2] ) ;
- endclosedline() ;
- popmatrix() ;
- }
-
- /*
- * Draw enemies as filled squares.
- */
- for( i = ENEMY ; i < numberPlayers ; i++ )
- {
- if( !EXPLODING( player+i ) && !CLOAKED( player+i ) )
- {
- c3f( teamColor[player[i].team] ) ;
- pushmatrix() ;
- translate( player[i].xyz[0], player[i].xyz[1],
- player[i].xyz[2] ) ;
- bgntmesh() ;
- v3f( blip[0] ) ;
- v3f( blip[1] ) ;
- v3f( blip[2] ) ;
- v3f( blip[3] ) ;
- endtmesh() ;
- popmatrix() ;
- }
- }
-
- /*
- * Draw cross hairs if in orbit.
- */
- if( selfStatus == OORT_ST_IN_ORBIT )
- {
- ortho2( -1.0f, 1.0f, -1.0f, 1.0f ) ;
- pfPushIdentMatrix() ;
- cpack( 0x0000ffff ) ;
- bgnline() ;
- c[0] = 0.0f ;
- c[1] = 0.1f ;
- v2f( c ) ;
- c[1] = -0.1f ;
- v2f( c ) ;
- endline() ;
- bgnline() ;
- c[0] = 0.1f ;
- c[1] = 0.0f ;
- v2f( c ) ;
- c[0] = -0.1f ;
- v2f( c ) ;
- endline() ;
- pfPopMatrix() ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Zoom the radar view in.
- *----------------------------------------------------------------------------*/
- void
- radarZoomIn(
- void
- )
- {
- if( radarSetting > 0 )
- {
- radarSetting-- ;
- radarAlt = radarMags[radarSetting] * ASTEROID_RADIUS ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Zoom the radar view out.
- *----------------------------------------------------------------------------*/
- void
- radarZoomOut(
- void
- )
- {
- if( radarSetting < ( sizeof(radarMags) / sizeof(radarMags[0]) ) - 1 )
- {
- radarSetting++ ;
- radarAlt = radarMags[radarSetting] * ASTEROID_RADIUS ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set radar setting to maximum range.
- *----------------------------------------------------------------------------*/
- void
- radarMaxRange(
- void
- )
- {
- radarSetting = ( sizeof(radarMags) / sizeof(radarMags[0]) ) - 1 ;
- radarAlt = radarMags[radarSetting] * ASTEROID_RADIUS ;
- }
-